﻿using Microsoft.Xna.Framework.Content;
using Phoenix.Xna.Framework.Graphics;
using Phoenix.Xna.Framework.Serialization;

namespace Phoenix.Xna.Framework.ContentPipeline.EffectMaps
{
    /// <summary>
    /// Reads and loads EffectMap files from the content pipeline.
    /// </summary>
    public class EffectMapReader : ContentTypeReader<EffectMap>
    {
        /// <summary>
        /// Reads and loads an EffectMap from the supplied content reader.
        /// </summary>
        /// <param name="input">The content reader to read the serialized data from.</param>
        /// <param name="existingInstance">An existing instance of the EffectMap to load the data into.</param>
        /// <returns>The deserialized EffectMap.</returns>
        protected override EffectMap Read(ContentReader input, EffectMap existingInstance)
        {
            string data = input.ReadString();
            EffectMap effectMap = new Serializer().Deserialize<EffectMap>(data);

            if (effectMap != null)
            {
                effectMap.LoadContent();
                existingInstance = effectMap;
            }

            return existingInstance;
        }
    }
}
